<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * @author Smarttang <[<yucong.tang@zhaopin.com.cn>]>
 * @date(2017.8.21)
 *
 * 功能业务接口
 */

class Feauitinterface extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('comon_model');
		$this->load->model('order_model');	
		$this->load->model('user_model');
		$this->load->model('power_model');
		$this->load->model('groupusers_model');
		$this->load->model('frame_model');
		$this->load->model('wafrules_model');
		$this->load->model('waf_model');
		
		
		// $this->load->helper('url');
		// $this->load->library('session');
	}

	/**
	 * 默认路由
	 * @return [type] [description]
	 */
	function index()
	{
		echo json_encode(array('status' => 0));
	}

	/**
	 * 核心路由
	 * @return [type] [description]
	 */
	function worker_routes()
	{
		// 方法选择
		$jump = $this->input->get_post('jump',TRUE);

		switch ($jump) {

			case 'behinds':
				if($this->comon_model->_userpower("0404000") < 0)
					die('{"status":-600}');
				$this->behinds($this->input);
				break;

			case 'users':
				if($this->comon_model->_userpower("0701000") < 0) 
					die('{"status":-600}');
				$this->users($this->input);
				break;

			case 'power':
				if($this->comon_model->_userpower("0703000") < 0) 
					die('{"status":-600}');
				$this->power($this->input);
				break;

			case 'groupusers':
				if($this->comon_model->_userpower("0702000") < 0) 
					die('{"status":-600}');
				$this->groupusers($this->input);
				break;
			case 'frame':
				$this->frame($this->input);
				break;

			case 'src':
				if($this->comon_model->_userpower("0704000") < 0) 
					die('{"status":-600}');
				$this->src($this->input);
				break;

			case 'wafrule':
				$this->wafrule($this->input);
				break;
			default:
				echo json_encode(array('status' => 0));
				break;
		}
	}

	/**
	 * 滞后事件的处理
	 * @param  [type] $inputs [description]
	 * @return [type]         [description]
	 */
	private function behinds($inputs)
	{
		$commonds = $inputs->post();

		switch ($commonds['commonds']) {

			// 添加滞后事件
			case 'add':
				echo json_encode($this->order_model->behind_add($commonds));
				break;

			// 添加的tab事件
			// 获取用户列表
			case 'addclick':
				echo json_encode($this->user_model->users_select());
				break;

			// 删除滞后事件
			case 'delete':
				echo json_encode($this->order_model->behind_delete($commonds));
				break;

			// 滞后事件的列表
			case 'list':
				echo json_encode($this->order_model->behind_list($commonds));
				break;
			
			// 读取单个滞后事件
			case 'read':
				echo json_encode($this->order_model->behind_read($commonds));
				break;

			default:
				echo json_encode(array('status' => 0));
				break;
		}
	}

	/**
	 * 用户的处理
	 * @param  [type] $inputs [description]
	 * @return [type]         [description]
	 */
	private function users($inputs)
	{
		$commonds = $inputs->post();

		switch ($commonds['commonds']) {

			// 添加滞后事件
			case 'add':
				echo json_encode($this->user_model->user_add($commonds));
				break;

			case 'list':
				echo json_encode($this->user_model->user_list($commonds));
				break;

			case 'groupuserslist':
				echo json_encode($this->user_model->groupusers_list());
				break;

			case 'del':
				echo json_encode($this->user_model->users_del($commonds));
				break;
			
			default:
				echo json_encode(array('status' => 0));
				break;
		}
	}

	/**
	 * 权限的处理
	 * @param  [type] $inputs [description]
	 * @return [type]         [description]
	 */
	private function power($inputs)
	{
		$commonds = $inputs->post();

		switch ($commonds['commonds']) {

			// 添加权限事件
			case 'add':
				if($this->comon_model->_userpower("0703001") < 0) 
					die('{"status":-600}');
				echo json_encode($this->power_model->power_add($commonds));
				break;

			//列表
			case 'list':
				if($this->comon_model->_userpower("0703002") < 0) 
					die('{"status":-600}');
				echo json_encode($this->power_model->power_list($commonds));
				break;

			//查询权限
			case 'powerDO':
				echo json_encode($this->power_model->powerDO_list());
				break;
			default:
				echo json_encode(array('status' => 0));
				break;
		}
	}

	/**
	 * 用户组的处理
	 * @param  [type] $inputs [description]
	 * @return [type]         [description]
	 */
	private function groupusers($inputs)
	{
		$commonds = $inputs->post();

		switch ($commonds['commonds']) {

			// 添加滞后事件
			case 'add':
				if($this->comon_model->_userpower("0702001") < 0) 
					die('{"status":-600}');
				echo json_encode($this->groupusers_model->groupusers_add($commonds));
				break;

			case 'list':
				echo json_encode($this->groupusers_model->groupusers_list($commonds));
				break;

			case 'addlist':
				echo json_encode($this->groupusers_model->groupusers_addlist($commonds));
				break;

			case 'del':
				echo json_encode($this->groupusers_model->groupusers_del($commonds));
				break;
			
			default:
				echo json_encode(array('status' => 0));
				break;
		}
	}

	/**
	 * 导航权限
	 * @param  [type] $inputs [description]
	 * @return [type]         [description]
	 */
	private function frame($inputs)
	{
		$commonds = $inputs->post();

		switch ($commonds['commonds']) {

			case 'list':
				echo json_encode($this->frame_model->frame_list());
				break;

			default:
				echo json_encode(array('status' => 0));
				break;
		}
	}

	/**
	 * src事件的处理
	 * @param  [type] $inputs [description]
	 * @return [type]         [description]
	 */
	private function src($inputs)
	{
		$commonds = $inputs->post();

		switch ($commonds['commonds']) {

			case 'list':
				echo json_encode($this->order_model->src_list($commonds));
				break;

			case 'add':
				echo json_encode($this->order_model->src_add($commonds));
				break;

			case 'push':
				echo json_encode($this->order_model->src_push($commonds));
				break;
				
			case 'assignusers':
				echo json_encode($this->order_model->srcAssignUsers_list($commonds));
				break;

			case 'assign':
				echo json_encode($this->order_model->srcAssign_push($commonds));
				break;
			
			//src工单删除
			case 'del':
				echo json_encode($this->order_model->src_del($commonds));
				break;

				//src事件推进流程弹出框状态
			case 'pushView':
				echo json_encode($this->order_model->srcPushView_list($commonds));
				break;

				//详情读取
			case 'read':
				echo json_encode($this->order_model->src_read($commonds));
				break;


				//IP区域读取
			case 'ipread':
				echo $this->comon_model->ipTOaddress($commonds);
				break;

				// 查询用户是否使我们冻结的
			case 'frozenIPStatusRead':
				echo $this->order_model->srcFrozenIPStatus_read($commonds);
				break;


				//解冻
			case 'frozen':
				echo $this->order_model->srcOpenFrozen_push($commonds);
				break;

				//查询企业信息
			case 'frozenInfoRead':
				echo $this->order_model->srcFrozenInfo_read($commonds);
				break;

			default:
				echo json_encode(array('status' => 0));
				break;
		}
	}

	
	/**
	 * waf规则的处理
	 * @param  [type] $inputs [description]
	 * @return [type]         [description]
	 */
	private function wafrule($inputs)
	{
		$commonds = $inputs->post();

		switch ($commonds['commonds']) {

			//列表
			case 'list':
				echo json_encode($this->wafrules_model->wafrule_list($commonds));
				break;

			//切换状态
			case 'statuschange':
				echo json_encode($this->wafrules_model->wafrulesStatus_change($commonds));
				break;

			//删除
			case 'del':
				echo json_encode($this->wafrules_model->wafrule_del($commonds));
				break;

			//读取详情
			case 'read':
				echo json_encode($this->wafrules_model->wafrule_read($commonds));
				break;

			//打开修改页面
			case 'changeread':
				echo json_encode($this->wafrules_model->wafrulechange_read($commonds));
				break;

			//确认修改
			case 'change':
				echo json_encode($this->wafrules_model->wafrule_change($commonds));
				break;

			default:
				echo json_encode(array('status' => 0));
				break;
		}
	}

	/**
	 * waf的处理
	 * @param  [type] $inputs [description]
	 * @return [type]         [description]
	 */
	private function waf($inputs)
	{
		$commonds = $inputs->post();

		switch ($commonds['commonds']) {

			//列表
			case 'list':
				echo json_encode($this->waf_model->waf_list($commonds));
				break;

			default:
				echo json_encode(array('status' => 0));
				break;
		}
	}
	


}
